<layout name="Layout/layout" />

<div id="wrapper">
    <div class="col-md-2">
        <include file="Layout:left-menubar" />
    </div>

    <div class="col-md-10">
    <!-- Page Content -->
    <div id="page-content-wrapper">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">
                    <h1>考点选择</h1>
                    <form id="select" class="form-horizontal" action="{:U('Home/Project/apply')}" method="post">
                        <div class="panel panel-default">
                            <div class="panel-body">
                                <div class="form-group">
                                    <label for="inputEmail3" class="col-sm-2 control-label">选择专业类别</label>
                                    <div class="col-sm-10">
                                        <select name="majorclass" id="disabledSelect" class="form-control">
                                            <foreach name="majorclass" item="v">
                                                <option value="{$v['id']}">{$v['name']}</option>
                                            </foreach>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">选择专业</label>
                                    <div class="col-sm-10">
                                        <foreach name="majornodes" item="v">
                                            <label class="checkbox-inline action-level">
                                                <input class="majors" name="majors[]" type="checkbox" value="{$v['id']}" pid="{$v['pid']}"> {$v['name']}
                                            </label>
                                        </foreach>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputEmail3" class="col-sm-2 control-label">考点</label>
                                    <div class="col-sm-10">
                                        <select name="examcenter" id="examcenter" class="form-control">
                                            <foreach name="examcenterlist" item="v">
                                                <option value="{$v['id']}">{$v['name']}</option>
                                            </foreach>
                                        </select>
                                    </div>
                                </div>
                                <input id="proid" type="hidden" name="proid" value="">
                                <div class="form-group">
                                    <div class="col-sm-offset-2 col-sm-10">
                                    <button id="query" type="button" class="btn btn-default">查询项目</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                    <hr />
                    <div class="projectlist">
                        <table class="table result">
                            <tr>
                                <th>项目名称</th>
                                <th>考点支持</th>
                                <th>专业</th>
                                <th>项目描述</th>
                                <th>操作</th>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /#page-content-wrapper -->
    </div>
</div>
<!-- /#wrapper -->
<script>
    window.onload = function(){
        $('#query').click(function(){
            var examcenter = $('#examcenter').val();
            var majors = [];
            $('input[name="majors[]"]:checked').each(function(){
                majors.push($(this).val());
            });
            $.post("{:U('Home/Project/getProjects')}",
            {
                examcenter: examcenter,
                majors: majors.join(),
            },
            function(data, status){
                var i;
                $('.temp').empty();
                for(i = 0; i < data.length; i++){
                    $('.result').append("<tr class=\"temp\"><td>"+ data[i]['name'] +"</td><td>" + data[i]['examcentername'] + "</td><td>" + data[i]['majorname'] + "</td><td>" + data[i]['title'] + "</td><td>" + "<a value=" + data[i]['id'] + " class=\"btn btn-success submit-btn\">报名</a>" + "</td></tr>");
                }
                bindform();
            });

        });
        function bindform(){
          $('.submit-btn').click(function(){
              $('#proid').val($(this).attr('value'));
              alert('请确认你选择的专业考点和项目的正确匹配，系统将根据你选择的选项计算需要缴纳的费用。');
              $('#select').submit();
          });
        }

    }
</script>
